# 步骤 1: 创建迭代器接口和具体迭代器
class NumberIterator:
    """具体迭代器"""
    def __init__(self, start, end):
        self.current = start
        self.end = end

    def __iter__(self):
        return self

    def __next__(self):
        if self.current > self.end:
            raise StopIteration
        else:
            result = self.current
            self.current += 1
            return result


# 步骤 2: 创建聚合接口和具体聚合
class NumberRange:
    """具体聚合类"""
    def __init__(self, start, end):
        self.start = start
        self.end = end

    def __iter__(self):
        return NumberIterator(self.start, self.end)


if __name__ == '__main__':
    # 创建一个数列
    num_range = NumberRange(1, 5)

    # 遍历数列
    for number in num_range:
        print(number)

'''
1
2
3
4
5
'''